package com.zyl.demo.service;

import com.zyl.demo.beans.Commodity;
import com.zyl.demo.mapper.CommodityMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityService {
    @Autowired
    CommodityMapper commodityMapper;

    public List<Commodity> getAllCommodity() {
        return commodityMapper.getAllCommodity();
    }

    public Commodity getCommodityById(int commodityId) {
        return commodityMapper.getCommodityById(commodityId);
    }

    public int deleteCommodity(int commodityId) {
        return commodityMapper.deleteCommodity(commodityId);
    }

    public List<Commodity> getRecommendList() {
        return commodityMapper.getRecommendList();
    }

    public List<Commodity> getCommodityByCategoryIdFive(int categoryId){
        return commodityMapper.getCommodityByCategoryIdFive(categoryId);
    }


    public List<Commodity> getCommodityPage(int startPage, int step) {
        return commodityMapper.getCommodityPage(startPage, step);
    }

    public List<Commodity> getCommodityByCategoryIdAndCategorySubId(int categoryId,int categorySubId,int page,int step) {
        if(categorySubId==-1){
            return commodityMapper.getCommodityByCategoryId(categoryId,page,step);
        }else{
            return commodityMapper.getCommodityByCategoryIdAndCategorySubId(categoryId,categorySubId,page,step);
        }
    }

}
